//
//  TempTimertager.m
//  3ikidsParents
//
//  Created by MyMac on 15/7/15.
//  Copyright (c) 2015年 KBTC. All rights reserved.
//

#import "TempTimertager.h"
@interface TempTimertager()
@property(nonatomic,weak)id target;
@property(nonatomic,assign)SEL selector;
@property(nonatomic,weak)NSTimer*timer;
@end
@implementation TempTimertager
-(void)fire:(NSTimer*)timer
{

    if(self.target){
         
        [self.target performSelector:self.selector withObject:timer.userInfo];
       // Log(@"%@",self.target);//<NewDisCoverHeaderView: 0x7fdc5c96bdf0; frame = (0 0; 375 326); autoresize = RM+BM; layer = <CALayer: 0x7fdc5c969600>>

    }else{
    
        [self.timer invalidate];
    
    }

}
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo
{

    TempTimertager*timerTarget=[[TempTimertager alloc]init];
    timerTarget.target=aTarget;
    timerTarget.selector=aSelector;
    //scheduled默认加到默认的runLoop，，，其他方法创建的timer需要手动驾到runLoop
    timerTarget.timer=[NSTimer  scheduledTimerWithTimeInterval:ti target:timerTarget.target selector:timerTarget.selector userInfo:userInfo repeats:yesOrNo];
   [[NSRunLoop currentRunLoop]addTimer:timerTarget.timer forMode:NSRunLoopCommonModes];
  
    
    
    return timerTarget.timer;

}
-(void)dealloc
{
     NSLog(@"%@  ***%@",self.timer,self);//0x7fa78af428d0    x7fa78af40e90 0x7fa78af428d0
    NSLog(@"自定义timer被释放了");

}
@end
